package com.example.thymeleaf.controller;

import com.example.thymeleaf.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@Controller
public class IndexController {

    @GetMapping("/")
    public String index(Model model) {
        model.addAttribute("username", "abc");
        return "index";
    }

    @GetMapping("each")
    public String each(Model model) {
        model.addAttribute("items", Arrays.asList("A", "B", "C"));

        model.addAttribute("users", Arrays.asList(new User(1, "name1"), new User(2, "name2")));
        return "index";
    }

    @GetMapping("map")
    public String map(Model model) {
        Map<String, Object> map = new HashMap<>();
        map.put("name", "abc");
        map.put("hobby", Arrays.asList("eat", "sleep"));
        map.put("users", Arrays.asList(new User(1, "name1")));
        model.addAttribute("map", map);
        return "index";
    }

}
